<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        //1
       /* function showMoney(){
            return this.money;
        }
        var personA = new Object;
        var personB = new Object;

        personA.money= "100";
        personB.money= "150";

        personA.showMoney= showMoney;
        personB.showMoney= showMoney;
        console.log(personA.showMoney( )); //"100"
        console.log(personB.showMoney( )); //"150"*/
        
        //2求和
      /*  function sum() {
            var nResult=0;
            for(var i=0;i<arguments.length;i++)
            {
                nResult +=  (!isNaN(arguments[i]) && window.parseFloat(arguments[i]))||0;
            }
            return nResult.toFixed(3) * 1000 / 1000;
        }
        alert(sum('1.0', false, 1, true, 1, 'A', 1, 'B', 1, 'C', 1, 'D', 1,
                'E', 1, 'F', 1, 'G', 1));
        alert(sum(0.1,0.2));*/
        
        //3.排序
       /* var data=[5,100,3,6,-12];
        function company(x,y) {
            return x-y;
        }
       data.sort(company);
        alert(data);*/

        //4.函数
       /* function makeCounter() {
            // 只能在makeCounter内部访问i
            var i = 0;
            return function () {
                console.log(++i);
            };
        }
        var counter = makeCounter();
        counter(); // logs: 1
        counter(); // logs: 2*/

        //5
       /* var a = 100;
        function fn() {
            alert(a);
            var a = 200;
            alert(a);
        }
        fn();//undeinedf,200
        alert(a);//100
        var a;
        alert(a);//100
        var a = 300;
        alert(a);//300*/

        //6
        /*var obj1 = {name: 'obj1', fn: function() {
           alert(this.name);
        }};
        var obj2 = {name: 'obj2'};
        var obj3 = {name: 'obj3'};
        obj1.fn();//obj
        var newFn = obj1.fn;
        newFn();//为空
        newFn.call(obj2);//obj2
        obj3.fn = newFn;
        obj3.fn();//obj3*/

        //7.二维数组排序
        /*var par=[[20,"ltt"],[25,"lx"],[22,"zt"]];
        par.sort(function (x,y) {
           return x[0]-y[0];
       });
        for(var i=0;i<par.length;i++)
        {
            console.log(par[i]);
        }*/
        //8.正则
       /* var str="abc345efgabcab";
        alert(str.replace(/[a-c]/g,""));
       /!* alert(str.replace(/(\d)/g,function (item) {
         item="["+item+"]";
         return item;
         }));*!/
        alert(str.replace(/(\d)/g,"[$1]"));
        alert(str.replace(/(\d)/g,function (item) {
            return item*2;
        }))*/

        //9
       // 请填充代码，使mySort()能使传入的参数按照从小到大的顺序显示出来。
        /*function mySort() {
            var tags = new Array();//使用数组作为参数存储容器
            for(var i=0;i<arguments.length;i++)
            {
                tags.push(arguments[i]);
            }
            tags=tags.sort(function (x,y) {
                return x-y;
            });
            return tags;//返回已经排序的数组
        }
        var result = mySort(50,11,16,32,24,99,57,100);//传入参数个数不确定
        console.info(result);//显示结果*/

        //10.给Array定义一个原型方法，它用于删除数组条目中重复的条目(可能有多个)，
        // 返回值是一个包含被删除的重复条目的新数组。
       /* Array.prototype.distinct = function() {
            var ret = [];
            for (var i = 0; i < this.length; i++)
            {
                for (var j = i+1; j < this.length;) {
                    if (this[i] === this[j]) {
                        ret.push(this.splice(j, 1)[0]);
                        //splice返回的是被删除的数组，所以是splice()[0];
                    }
                    else {
                        j++;
                    }
                }
            }
            return ret;
        };
        //for test 'a','b','c','d','b','a','e'
        alert(['a','b','a','b','a'].distinct());


        //11.数组去重
         function distict(data) {
             var ret=[],b=[];
             for(var i=0;i<data.length;i++)
             {
                 if(ret.indexOf(data[i])<0)
                 {
                     ret.push(data[i]);
                 }
             }
             return ret;
         }*/

            //11.用javascript实现用户登录验证的代码。
        //console.log(1+ +"2"+"2");
        /*第一个+"2"中的加号是一元加操作符，+"2"会变成数值2，因此1+ +"2"相当于1+2=3.
        然后和后面的字符串“2”相合并，变成了字符串"32".*/

      /*  var myObject={
            foo:"bar",
            func:function () {
                var self=this;
                console.log(this.foo);//bar,this是指向myObject
                console.log(self.foo);//bar
                (function () {
                    console.log(this.foo);//undefined,this指向的是window
                    console.log(self.foo);
                })();
            }
        };
        myObject.func();

        var foo={n:1};
        (function (foo) {
            console.log(foo.n);
            foo.n=3;
            var foo={n:2};
            console.log(foo.n);
        })(foo);
        console.log(foo.n);

        console.log(([])?true:false);
        console.log(([]==false?true:false));
        console.log(({}==false)?true:false)*/

        /*function check() {
            var name=document.getElementById("username").value;
            var password=document.getElementById("password").value;
            if(name==""||password==""){
                alert("请输入用户名和密码");
                return false;
            }
            else
                    return true;
        }*/
    /*    alert(5*015===5.075);*/
        /*var a=[1,2,3,4,5];
        a.splice(0,1);
        alert(a);
        alert(13&5);*/
        //获取当前日期的月份
        /*var today=new Date();
        var time=[7,1,2,3,4,5,6];
        alert(time[today.getDay()]);*/
        var a=13;
        alert(a.toString(2));
    </script>
</body>
</html>